#!/usr/bin/node
const EventEmitter = require('events').EventEmitter;

function Dog(name,energy){
  let _name = name,//私有属性
      _energy = energy,//私有属性
      that = this;

  EventEmitter.call(this);

  let timer = setInterval(()=>{
    if (_energy>0){
      that.emit('bark');//事件：bark事件
      _energy--;
    }else{
      clearInterval(timer);
    }
  },1000);
  this.name = ()=> _name;//方法
  this.energy = ()=>_energy;//方法
}

Dog.prototype = EventEmitter.prototype;

module.exports = Dog;
